package com.itany.corejava.day06;

import java.util.Arrays;
import java.util.Scanner;

public class Test1 {

    public static String[][] chess=new String[16][16];

    static{
        System.out.print("  ");
        for (int i = 0; i < 16; i++) {
            //10进制数字转16进制字符串
            System.out.print(Integer.toHexString(i)+" ");
        }
        System.out.println();

        for (int i = 0; i < chess.length; i++) {
            System.out.print(Integer.toHexString(i)+" ");
            for (int j = 0; j < chess[i].length; j++) {
                chess[i][j]="*";
                System.out.print(chess[i][j]+" ");
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean isBlack=true;
        do {

            //提示用户哪方落子
            System.out.println((isBlack?"黑":"白")+"方落子");

            //用户输入坐标
            String point=sc.nextLine();

            //将输入的坐标转换成数组的i，j
            char[] c=point.toCharArray();
            String m=c[0]+"";
            String n=c[1]+"";
            //16进制字符串转10进制数字
            int i=Integer.parseInt(m,16);
            int j=Integer.parseInt(n,16);



            //落子
            if(!"*".equals(chess[i][j])){
                System.out.println("该位置已经有棋子");
                continue;
            }
            chess[i][j]=isBlack?"@":"0";

            //打印棋盘
            print();

            //判断输赢
            if(a(i,j)>=5||b(i,j)>=5||c(i,j)>=5||d(i,j)>=5){
                System.out.println(isBlack?"黑方赢":"白方赢");
                break;
            }

            //换方
            isBlack=!isBlack;
        }while (true);
    }

    public static int a(int i,int j){
        int num=1;

        int i1=i;
        int j1=j-1;

        int i2=i;
        int j2=j+1;

        while(j1!=-1&&chess[i][j].equals(chess[i1][j1])){
            num++;
            j1--;
        }

        while(j2!=16&&chess[i][j].equals(chess[i2][j2])){
            num++;
            j2++;
        }

        return num;
    }
    public static int b(int i,int j){
        return 0;
    }
    public static int c(int i,int j){
        return 0;
    }
    public static int d(int i,int j){
        return 0;
    }


    public static void print(){
        System.out.print("  ");
        for (int i = 0; i < 16; i++) {
            //10进制数字转16进制字符串
            System.out.print(Integer.toHexString(i)+" ");
        }
        System.out.println();

        for (int i = 0; i < chess.length; i++) {
            System.out.print(Integer.toHexString(i)+" ");
            for (int j = 0; j < chess[i].length; j++) {
                System.out.print(chess[i][j]+" ");
            }
            System.out.println();
        }
    }


}
